/**********************************************************************
 *   Copyright: (C)2024 LingYun IoT System Studio
 *      Author: LiJiahui<2199250859@qq.com>
 *
 * Description: The purpose of this code is to provide a simple C library,
 *              which providing software bit-bang of the I2C protocol on
 *              any GPIO pins for ISKBoard.
 *
 *   ChangeLog:
 *        Version    Date       Author            Description
 *        V1.0.0  2025.07.18    LiJiahui      Release initial version
 *
 ***********************************************************************/
#ifndef __BLE_SEND_H__
#define __BLE_SEND_H__


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>


#include "miscdev.h"
#include "ntp_client.h"
#include "usart.h"
#include "project_tasks.h"
#include "FreeRTOS.h"

#define MAX_RETRY_ATTEMPTS 3 // 设置最大重试次数
#define CMD_TIMEOUT_MS     5000 // 命令响应超时时间
#define MUTEX_TIMEOUT_MS   5000 // 获取互斥锁的超时时间
#define RETRY_DELAY_MS     1000 // 每次重试之间的延时

// 定义 BLE 初始化相关的错误码
#define BLE_INIT_SUCCESS          0
#define BLE_INIT_FAILURE_AT       -1
#define BLE_INIT_FAILURE_INIT     -2
#define BLE_INIT_FAILURE_SRVCRE   -3
#define BLE_INIT_FAILURE_SRVSTART -4
#define BLE_INIT_FAILURE_ADVDATA  -5
#define BLE_INIT_FAILURE_ADVSTART -6
#define BLE_INIT_FAILURE_MUTEX    -7

/* ---ESP8266  AT指令响应字符串--- */
#define BLE_RESPONSE_OK		"OK" /* 成功执行后的响应 */
#define BLE_RESPONSE_ERROR	"ERROR" /* 执行指令出错 */
#define BLE_RESPONSE_FAIT	"FAIL" /* 执行指令失败 */

int ble_module_init(SemaphoreHandle_t xUartMutex);
int ble_adv_start(SemaphoreHandle_t xUartMutex);
int ble_send_sensor_data(SemaphoreHandle_t xUartMutex, uint16_t heart_rate, uint16_t spo2);

#endif
